import { getUserInfo } from "../../utils/auth"

Page({
  data: {
    user:{},
    userType:'',
    avatarUrl:'',
    content:[
      {title:'用户管理',detail:[{title:'辖区用户', Icon:'../../images/user.png'}, {title:'个人积分', Icon:'../../images/score.png'}]}
    ]
  },
  
  onShow() {
    const user = getUserInfo()
    // 需要考虑更新完之后，重新刷新
    if(user && user.avatarUrl){
      this.setData({
        avatarUrl: user.avatarUrl
      })
    }
    // 可能需要重新写
    switch(user.roles.length){
      case 3:
        this.setData({
          user,
          userType: '队站管理员'
        })
        break;
      case 2:
        this.setData({
          user,
          userType: '管理员'
        })
        break;
      case 1:
        this.setData({
          user,
          userType: '普通用户'
        })
        break;
      default:
        this.setData({
          user,
          userType: "未登录"
        })
    }
  },

  updateInfo() {
    wx.navigateTo({
      url: `../userInfo/index?avatarUrl=${encodeURIComponent(this.data.avatarUrl)}&userType=${this.data.userType}`
    })
  },

  clickCard(e){
    let item = e.detail
    let companyId = this.data.user.company.id
    switch(item.title){
      case '个人积分':
        console.log('个人积分')
        break;
      case '辖区用户':
        wx.navigateTo({
          url: `../stationUser/index?userType=${this.data.userType}&companyId=${companyId}`,
        })
        break;
    }
   
  },
  
  login(){
    wx.navigateTo({
      url: '../login/index',
    })
  }
  
})

